package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.AtlasMapper;
import org.rcloud.io.model.Atlas;
import org.rcloud.io.service.AtlasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/2/28.
 */
@Service(value = "AtlasService")
public class AtlasServiceImpl implements AtlasService{

    @Autowired
    private AtlasMapper atlasMapper;


    @Override
    public ResultVo saveAtlas(Atlas atlas) {

        if (atlas.equals("") || atlas == null){
            return ResultVo.setError("数据为空");
        } else {
            try {
                atlasMapper.insertSelective(atlas);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public PageVo<Atlas> findAllAtlas() {

        try {
            List<Atlas> list = atlasMapper.selectAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo findAtlasById(String id) {

        if (id.equals("") || id == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                Atlas atlas = atlasMapper.selectByPrimaryKey(id);
                return ResultVo.setOK(atlas);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo updateById(Atlas atlas) {

        if (atlas.equals("") || atlas == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                atlasMapper.updateByPrimaryKeySelective(atlas);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo findAtlasByNum(String num) {

        if (num.equals("") || num == null){
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                Atlas atlas = atlasMapper.selectByNum(num);
                return ResultVo.setOK(atlas);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }


}
